package com.example.test

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.ScrollView
import android.widget.TextView

class MainActivity : AppCompatActivity() {
    private lateinit var scrollView: ScrollView
    private lateinit var textContainer: LinearLayout
    private lateinit var addTextViewBtn: Button
    private lateinit var resultText: TextView
    private lateinit var submitBtn: Button
    private val advisorModel = AdvisorModel()
    private var textViewCount = 1

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // 明确泛型，解决类型推断问题
        scrollView = findViewById<ScrollView>(R.id.scroll_view)
        textContainer = findViewById<LinearLayout>(R.id.text_container)
        addTextViewBtn = findViewById<Button>(R.id.add_textview_btn)
        resultText = findViewById<TextView>(R.id.result_text)
        submitBtn = findViewById<Button>(R.id.submit_btn)

        addTextViewBtn.setOnClickListener {
            val newTextView = TextView(this)
            // 使用字符串资源+占位符，解决setText拼接警告
            newTextView.text = getString(R.string.new_textview_text, textViewCount.toString())
            textViewCount++
            textContainer.addView(newTextView)
        }

        submitBtn.setOnClickListener {
            val advisorInfo = advisorModel.getAdvisorInfo()
            resultText.text = advisorInfo
        }
    }
}